package org.wyn.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.wyn.common.ResultType;
import org.wyn.mongodb.bean.User;
import org.wyn.mongodb.bean.UserDetail;
import org.wyn.service.IProfileService;

import com.google.inject.Inject;

/**
 * 个人主页action
 * @author wyn
 *
 */
@Namespace("/profile")
@ParentPackage("security")
public class ProfileAction extends WynActionSupport{
	
	/**
	 * 进入个人主页
	 * @return
	 */
	@Action(value="goProfile",results = {@Result(name = SUCCESS, type = ResultType.FREEMARKER, location = "profile.ftl")})
	public String goProfile(){
		ud = iProfileService.getUserDetailByUserName(getLoginUserName());
		return SUCCESS;
	}
	/**
	 * 进入别人的主页
	 * @return
	 */
	@Action(value="goOtherProfile",results = {@Result(name = SUCCESS, type = ResultType.FREEMARKER, location = "other_profile.ftl")})
	public String goOtherProfile(){
		User user = getLoginUser();
		iProfileService.visitOtherProfile(otherUserName, user.getUserName());
		//被查看用户的用户信息
		getRequest().setAttribute("otherUd", iProfileService.getUserDetailByUserName(otherUserName));
		return SUCCESS;
	}
	private String otherUserName;
	private UserDetail ud;
	@Inject
	private IProfileService iProfileService;
	private static final long serialVersionUID = 1L;
	public String getOtherUserName() {
		return otherUserName;
	}
	public void setOtherUserName(String otherUserName) {
		this.otherUserName = otherUserName;
	}
	public IProfileService getiProfileService() {
		return iProfileService;
	}
	public void setiProfileService(IProfileService iProfileService) {
		this.iProfileService = iProfileService;
	}
	public UserDetail getUd() {
		return ud;
	}
	public void setUd(UserDetail ud) {
		this.ud = ud;
	}

}
